package net.esj.basic.expression.condition.logic;

import net.esj.basic.expression.ExpressionException;
import net.esj.basic.expression.condition.Condition;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Scope("prototype")
@Component("notCondition")
public class ConditionLogicNot extends AbstractConditionLogic {

	
	
	public ConditionLogicNot() {
		super();
	}

	@Override
	public boolean passed(Number num) throws ExpressionException {
		for(Condition c:conditions){
			return !c.passed(num);
		}
		return true;
	}
	
	public void addCondition(Condition cond){
		if(conditions.length>=1){
			throw new ArrayIndexOutOfBoundsException("Only one Condition can be used in Not logic Condition,please check your template!");
		}
		super.addCondition(cond);
	}

}
